<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        #box {
            width: 400px;
            height: 600px;
            border: 1px solid red;
            margin: 0 auto;
        }

        #box img {
            width: 360px;
            height: 410px;
            margin: 20px 20px 5px 20px;
        }

        #box {
            font-size: 12px;
            color: gray;
            text-align: center;
        }

        #box h2 {
            font-size: 24px;
            color: #333;
            text-align: center;
            font-weight: bold;
            margin: 5px 0 20px 0;
        }

        #box span {
            font-size: 12px;
            color: gray;

        }

        #text1 {
            width: 50px;
            height: 25px;
            text-align: center;
        }

        #btn1,
        #btn2 {
            width: 30px;
            height: 30px;

        }

        #count {
            font-size: 16px;
            color: #333;
            text-align: center;
            margin-top: 10px;
        }
    </style>
</head>

<body>
    <div id="box">
        <img src="../images/2.jpg" alt="">
        <p>寄樊希&nbsp;&nbsp;小羊皮口红304</p>
        <h2>
            ￥&nbsp;340
        </h2>
        <span>数量
            <button id="btn1">-</button>
            <input type="text" value="0" id="text1">
            <button id="btn2">+</button>

        </span>
        <h3 id="count">总价：<i id="total"></i></h3>
    </div>
    <script>
        btn1.onclick = function () {

            var a = parseInt(text1.value) - 1
            text1.value = a;

            if (text1.value <= 0) {
                text1.value = 0;
            }
            total.innerHTML = 340 * text1.value
        }
        btn2.onclick = function () {
            var b = parseInt(text1.value) + 1
            text1.value = b;
            total.innerHTML = 340 * text1.value
        }





    </script>
</body>

</html>